import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
        
        let batteryChannel = FlutterMethodChannel(name: "com.example.com/battery",
                                                  binaryMessenger: controller.binaryMessenger)
        batteryChannel.setMethodCallHandler({
            (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
            // This method is invoked on the UI thread.
            // This method is invoked on the UI thread.
            guard call.method == "getBatteryLevel" else {
                result(FlutterMethodNotImplemented)
                return
            }
            
            // BatteryManage.receiveBatteryLevel(result: result)
            let manage = BatteryManage()
            manage.getBatteryLevel(result: result)
        })
        
        GeneratedPluginRegistrant.register(with: self)
        
        // CustomViewPlugin.registerWith(registry: self)
        CustomViewPlugin.register(with: self.registrar(forPlugin: "plugins/view")!)
        
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
}
